﻿using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace WebApiOrm.Provider
{
    /// <summary>
    /// orm工厂选项
    /// </summary>
    public record OrmFactoryOptions  
    {
        private readonly Dictionary<string, Type> ormMap = new(StringComparer.OrdinalIgnoreCase);

        public IEnumerable<string> Names => this.ormMap.Keys;

        /// <summary>
        /// 设置提供者
        /// </summary>
        /// <typeparam name="TOrmProvider"></typeparam>
        /// <param name="ormName">orm名称</param>
        public void SetProvider<TOrmProvider>(string ormName) where TOrmProvider : IOrmProvider
        {
            this.ormMap[ormName] = typeof(TOrmProvider);
        }


        /// <summary>
        /// 尝试获取提供者的类型
        /// </summary>
        /// <param name="ormName">orm名称</param>
        /// <param name="ormProviderType"></param>
        /// <returns></returns>
        public bool TryGetProviderType(string ormName, [MaybeNullWhen(false)] out Type ormProviderType)
        {
            return this.ormMap.TryGetValue(ormName, out ormProviderType);
        } 
    }
}
